<?php
/**
*	Written by David Meng <md-chinese@163.com>
*	http://www.systn.com
*	Version:ET.E2.20071130
*/

define("Ease Template!",TRUE);
class template{
	var $ThisFile	= '';				//当前文件
	var $IncFile	= '';				//引入文件
	var $ThisValue	= array();			//当前数值
	var $FileList	= array();			//载入文件列表
	var $IncList	= array();			//引入文件列表
	var $ImgDir		= array('images');	//图片地址目录
	var $HtmDir		= 'cache_htm/';		//静态存放的目录
	var $HtmID		= '';				//静态文件ID
	var $HtmTime	= '180';			//秒为单位，默认三分钟
	var $AutoImage	= 1;				//自动解析图片目录开关默认值
	var $Hacker		= "<?php if(!defined('Ease Template!')){die('You are Hacker!<br>Power by Ease Template!');}?>";
	
	var $Compile = array(
			'/(\{\s*|<!--\s*)inc_php:([^<>]{1,100})(\s*\}|\s*-->)/eis',
			
			'/<!--\s*DEL\s*-->/is',
			'/<!--\s*IF(\[|\()(.+?)(\]|\))\s*-->/is',
			'/<!--\s*ELSEIF(\[|\()(.+?)(\]|\))\s*-->/is',
			'/<!--\s*ELSE\s*-->/is',
			'/<!--\s*END\s*-->/is',
			'/<!--\s*([a-zA-Z0-9_\$\[\]\'\"]{2,60})\s*(AS|as)\s*(.+?)\s*-->/',
			'/<!--\s*while\:\s*(.+?)\s*-->/is',
			
			'/(\{\s*|<!--\s*)lang\:(.+?)(\s*\}|\s*-->)/eis',
			'/(\{\s*|<!--\s*)row\:(.+?)(\s*\}|\s*-->)/eis',
			'/(\{\s*|<!--\s*)color\:\s*(.+?)(\s*\}|\s*-->)/eis',
			'/(\{\s*|<!--\s*)dir\:([^\{\}]{1,100})(\s*\}|\s*-->)/eis',
			'/(\{\s*|<!--\s*)run\:(\}|\s*-->)\s*(.+?)\s*(\{|<!--\s*)\/run(\s*\}|\s*-->)/is',
			'/(\{\s*|<!--\s*)run\:(.+?)(\s*\}|\s*-->)/is',
			'/\{([a-zA-Z0-9_\'\"\[\]\$]{1,100})\}/',
	   );
		
	var $Analysis = array(
			'$this->inc_php("\\2")',
			
			'<?if($ET_Del==true){?>',
			'<?if(\\2){?>',
			'<?}elseif(\\2){?>',
			'<?}else{?>',
			'<?}?>',
			'<?\$_i=0;\\1=(is_array(\\1))?\\1:array();foreach(\\1 AS \\3){\$_i++;?>',
			'<?\$_i=0;while(\\1){\$_i++;?>',
			
			'$this->lang("\\2")',
			'$this->Row("\\2")',
			'$this->Color("\\2")',
			'$this->Dirs("\\2")',
			'<?\\3;?>',
			'<?\\2;?>',
			'<?echo \$\\1;?>',
	   );
	
	/**
	*	声明模板用法
	*/
	function template(
		$set = array(
				'ID'		 =>'1',					//缓存ID
				'TplType'	 =>'htm',				//模板格式
				'CacheDir'	 =>'cache',				//缓存目录
				'TemplateDir'=>'template' ,			//模板存放目录
				'AutoImage'	 =>'on' ,				//自动解析图片目录开关 on表示开放 off表示关闭
				'LangDir'	 =>'language' ,			//语言文件存放的目录
				'Language'	 =>'default' ,			//语言的默认文件
			)
		){
		
		$this->TplID		= (defined('TemplateID')?TemplateID:( ((int)$set['ID']<=1)?1:(int)$set['ID']) ).'_';
		
		$this->CacheDir   	= (defined('NewCache')?NewCache:( (trim($set['CacheDir'])!='')?$set['CacheDir']:'cache') ).'/';
		
		$this->TemplateDir	= (defined('NewTemplate')?NewTemplate:( (trim($set['TemplateDir'])!='')?$set['TemplateDir']:'template') ).'/';
		
		$this->Ext			= ($set['TplType']!='')?$set['TplType']:'htm';
		
		$this->AutoImage	= ($set['AutoImage']=='off')?0:1;
		
		$this->Server		= (is_array($GLOBALS['_SERVER']))?$GLOBALS['_SERVER']:$_SERVER;
		
		$this->LangDir		= (defined('LangDir')?LangDir:( (($set['LangDir']!='language' && $set['LangDir'])?$set['LangDir']:'language') )).'/';
		if(is_dir($this->LangDir)){
			//载入语言文件
			$this->Language	= (defined('Language')?Language:( (($set['Language']!='default' && $set['Language'])?$set['Language']:'default') ));
			if(@is_file($this->LangDir.$this->Language.'.php')){
				$lang = array();
				@include_once $this->LangDir.$this->Language.'.php';
				$this->LangData = $lang;
			}
		}
		
		//缓存目录检测以及运行模式
	   	$this->RunType		= (@substr(@sprintf('%o', @fileperms($this->CacheDir)), -3)!=777)?'Replace':'Cache';
	}
	
	
	/**
	*	设置数值
	*	set_var(变量名或是数组,设置数值[数组不设置此值]);
	*/
	function set_var(
				$name, 
				$var = ''
			){
		if (is_array($name)){
			$this->ThisValue = @array_merge($this->ThisValue,$name);
		}else{
			$this->ThisValue[$name] = $var;
		}
	}
	
	
	/**
	*	设置模板文件
	*	set_file(文件名,设置目录);
	*/
	function set_file(
				$FileName,
				$NewDir = ''
			){
		
		$this->ThisFile  = $FileName.'.'.$this->Ext;
		
		//目录地址检测
		$this->FileDir[$this->ThisFile] = (trim($NewDir)!='')?$NewDir.'/':$this->TemplateDir;
		
		$IncFile		 = $this->FileDir[$this->ThisFile].$this->ThisFile;
		if(!is_file($IncFile)){
			die('Sorry, The file <b>'.$IncFile.'</b> does not exist.');
		}
		
		//bug 系统
		$this->IncList[] = $IncFile;
	}
	
	
	/**
	*  检测引入文件
	*/
	function inc_php(
				$url = ''
			){
		
		$parse	= parse_url($url);
		$exps	= explode('&',$parse['query']);
		unset($vals,$code_array);
		foreach($exps AS $vals){
			$vale = explode('=',$vals);	//拆分
			$valr = trim(preg_replace('/\{([a-zA-Z0-9_\'\"\[\]\$]+)\}/',"\$\\1",$vale[1]));
			if(trim($vale[0])){
				$code_array .= '$'.$vale[0].'='.((ereg('\$',$valr))?$valr:"'".$valr."'").';';
			}
		}
		
		return '<?'.$code_array.' include(\''.$parse['path'].'\');?>';
	}
	
	
	
	//编译缓存文件包括连载功能
	function Compile(
				$FileName	= '',
				$kind		= '',
				$temp		= ''
			){
		if($kind!='' && count($this->FileList)>0 && !file_exists($this->CacheDir.$kind.'.php')){
			$KindData = '';
			foreach($this->FileList AS $k=>$v){ $KindData .= $this->CompilePHP($this->Compile($v.$k,'',1)); }
			
			$this->writer($this->FileName($kind,$this->TplID) ,$this->Hacker.$KindData);
		}elseif($temp==1){
			//inc
	 		$SourceFile  = ($FileName == '') ? $this->FileDir[$this->ThisFile].$this->ThisFile : $FileName;
			if(!in_array($SourceFile,$this->FileList)){
				$content = $this->reader($SourceFile);
				
				//include
				$content = $this->inc_preg($content);
				
				return $content = @preg_replace($this->Compile, $this->Analysis, $content);
			}
		}else{
	 		$SourceFile  = ($FileName == '') ? $this->FileDir[$this->ThisFile].$this->ThisFile : $FileName;
			if(!in_array($SourceFile,$this->FileList)){
				$content = $this->reader($SourceFile);
				
				//include
				$content = $this->inc_preg($content);
				
				$content = $this->CompilePHP($content, 'kind');
				
				$this->writer($this->FileName($this->ThisFile,$this->TplID) ,$this->Hacker.$content);
			}
		}
	}
	
	
	function n(){
		$this->FileList[$this->ThisFile] = $this->FileDir[$this->ThisFile];
		//文件日期(用于对比最新时间更新模板)
		$this->FileDate[] = @filemtime($this->FileDir[$this->ThisFile].$this->ThisFile);
	}
	
	
	/**
	*	输出模板内容
	*/
	function r(
				$kind=''
			){
		if($this->RunType=='Cache'){
			return ($kind=='include_page')?$this->ParsePHP($kind):$this->ParseHtml($kind);
		}else{
			if($kind){
				$kind = ($kind=='include_page')?'include_page':$this->FileList;
				return $this->ParseCode($kind);
			}else{
				return $this->ParseCode();
			}
		}
	}
	
	
	/**
	*	打印模板内容
	*/
	function p(
				$kind=''
			){
		if($this->RunType=='Cache'){
			echo ($kind=='include_page')?$this->ParsePHP($kind):$this->ParseHtml($kind,'print');
		}else{
			if($kind){
				$kind = ($kind=='include_page')?'include_page':$this->FileList;
				echo $this->ParseCode($kind);
			}else{
				echo $this->ParseCode();
			}
		}
	}
	
	
	//解析替换程序
	function ParseCode(
				$FileList=''
			){
		//解析续载
		if (@is_array($FileList) && $FileList!='include_page'){
			$ShowTPL = '';
			foreach ($FileList AS $K=>$V) {
				$ShowTPL .= $this->reader($V.$K);
			}
		}else{
			
			$SourceFile = $this->FileDir[$this->ThisFile].$this->ThisFile;
			
			if(!is_file($SourceFile)){
				die('Sorry, The file <b>'.$SourceFile.'</b> does not exist.');
			}
			
			$ShowTPL = $this->reader($SourceFile);
			
			if ($FileList=='include_page'){
				return $ShowTPL;
			}
		}
		
		//File Leng
		$ReadSize = strlen($ShowTPL);
		
		//include
		$ShowTPL = $this->inc_preg($ShowTPL);
		
		//Fix =
		$ShowTPL = preg_replace('/(\{|<!--\s*)run:(\}|\s*-->)\s*=/','{run:}echo ',$ShowTPL);
		$ShowTPL = preg_replace('/(\{|<!--\s*)run:\s*=/','{run:echo ',$ShowTPL);
		
		
		//Fix Run 1
		$ShowTPL = preg_replace('/(\{|<!--\s*)run\:(\}|\s*-->)\s*(.+?)\s*(\{|<!--\s*)\/run(\}|\s*-->)/is', '(T_T)\\3;(T_T!)',$ShowTPL);
		
		
			foreach($this->Analysis AS $A_k => $A_v){
			   $A_v = str_replace('<?','(^_^);',$A_v);
			   $A_v = str_replace('?>','echo(^_^)',$A_v);
		   	   $this->Analysis[$A_k] = $A_v;
			}
			$ShowTPL = str_replace('\\','\\\\',$ShowTPL);
			$ShowTPL = str_replace('"','\"',$ShowTPL);
			
 			$ShowTPL = @preg_replace($this->Compile, $this->Analysis, $ShowTPL);
			
			$ShowTPL = str_replace('<?','(^_^);',$ShowTPL);
			$ShowTPL = str_replace('?>','echo(^_^)',$ShowTPL);
			
 			$ShowTPL = $this->ImgCheck($ShowTPL);
 			
 			//Fix javascript
 			$ShowTPL = str_replace('$','\$',$ShowTPL);
 			
			$ShowTPL = @preg_replace("/\(\^_\^\);(.+?)echo\(\^_\^\)/e", '$this->FixPHP(\'\\1\')', $ShowTPL);
			
			$ShowTPL = str_replace('(^_^)','"','echo (^_^)'.$ShowTPL.'(^_^);');
			
			//Fix Run 2
			$ShowTPL = preg_replace("/\(T_T\)(.+?)\(T_T!\)/ise", '$this->FixRun(\'\\1\')', $ShowTPL);
			
			//从数组中将变量导入到当前的符号表
			@extract($this->Value());
			ob_start();
				@eval($ShowTPL);
				$contents = ob_get_contents();
			ob_end_clean();
			
			//错误检查
			if(strlen($contents)<=0){
				die('Sorry, Error or complicated syntax error exists in '.$SourceFile.' file.');
			}
		return $contents;
	}
	
	
	//修复PHP执行时产生的错误
	function FixRun(
				$content=''
			){
		$content = str_replace('\$','$',$content);
		$content = str_replace('\\\\','\\',$content);
		$content = str_replace('\\\\"','\\\\"',$content);
		$content = str_replace('\"','"',$content);
 		$content = preg_replace('/\/\/.+?((.|\n)*)/is',"",$content);
		return '";'.$content.'echo "';
	}
	
	
	//修复PHP执行时产生的错误
	function FixPHP(
				$content=''
			){
		return '(^_^);'.str_replace('\\\\"','"',str_replace('\$','$',$content)).'echo(^_^)';
	}
	
	
	function ParsePHP(
				$FileName = ''
			){
			if($FileName == '' || $FileName == 'include_page'){
				$SourceFile = $this->FileDir[$this->ThisFile].$this->ThisFile;
				if($FileName == 'include_page'){
					return $this->reader($SourceFile);
				}
			}else{
				$SourceFile = $FileName;
			}
			//从数组中将变量导入到当前的符号表
			@extract($this->Value());
			ob_start();
				$this->IncFile = $SourceFile;
			  	@include_once($SourceFile);
				$contents = ob_get_contents();
			ob_end_clean();
			
			//Cache htm
			if($this->HtmID){
				$this->writer($this->HtmDir.$this->HtmID,$this->Hacker.$contents);
			}
			
		return @preg_replace('/ET>(.+?)<\/ET/is', '?\\1?', $contents);
	}
	
	
	function ParseHtml(
				$kind = '',
				$pt = ''
			){
		if($kind!=''){
			@rsort ($this->FileDate);
			@reset ($this->FileDate);
			$NowTime = $this->FileDate[0];
			$Parse   = $this->FileName($kind,$this->TplID);
   		}else{
			$NowTime = (int)@filemtime($this->FileDir[$this->ThisFile].$this->ThisFile);
			$Parse   = $this->FileName($this->ThisFile,$this->TplID);
		}
		
		if($NowTime > (int)@filemtime($Parse)){
  			$this->Compile('',$kind);
		}
		
		if($pt=='print'){
			if($kind!='' && is_file($this->FileName($kind,$this->TplID))){
				@extract($this->Value());
			  	include_once($this->FileName($kind,$this->TplID));
			}else{
				echo $this->ParseHtml($kind);
			}
		}else{
  		   return $this->ParsePHP($Parse);
		}
	}
	
	
	//引用函数
	function inc(
				$Files = '',
				$Types = 0
			){
		if($Files){
			if($Types==0){
				$heads = ($this->RunType=='Cache')?"<!--ET:".base64_encode($Files)."-->":'';
				return $heads.$this->Compile($Files,'',1);
			}else{
				$this->IncList[]  = $Files;
				$Content = $this->reader($Files);
				return $this->inc_preg($Content);
			}
		}
	}
	
	
	/**
	*	解析文件
	*/
	function FileName(
				$name,
				$id = '1'
			){
		$extdir = explode("/",$name);
		$dircnt = @count($extdir) - 1;
		$extdir[$dircnt] = $id.$extdir[$dircnt];
		return $this->CacheDir.implode("_",$extdir).".".$this->Language.'.php';
	}
	
	
	/**
	*  多语言
	*/
	function lang(
				$str = ''
			){
		//采用MD5效验
		$id 	 = md5($str);
		
		//不存在数据则写入
		if(!@array_key_exists($id, $this->LangData) && $this->Language=='default'){
			
			//修复'多\问题
			$str = str_replace("\'","'",$str);
			
			$docs= str_replace('\"','"',$str);
			
			//输出数据
			$out = $docs;
			
			if($this->RunType!='Replace'){
				$str = str_replace('"','\"',$str);
				$out = $docs;
			}
			
			//语言文件过大时采取建立新文件
			if(strlen($docs)>400){
				$this->writer($this->LangDir.$this->Language.'.'.$id.'.php','<? $etl = "'.$str.'";?>');
				
				$docs= substr($docs,0,40);		//简要说明
				$str = 'o(O_O)o.ET Language.o(*_*)o';	//语言新文件
			}
			
			//文件安全处理
			$data = (!is_file($this->LangDir.'default.php'))?"<?\n/**\n/* SYSTN ET Language\n*/\n\n\n":'';
			
			//写入数据
			$data .= "/**".date("Y.m.d",time())."\n";
			$data.= $docs."\n";
			$data.= "*/\n";
			$data.= '$lang["'.$id.'"] = "'.$str.'";'."\n\n";
			$this->writer($this->LangDir.'default.php',$data,'a+');
		}else{
			//当数据不在当前语言包中将载入默认包中语言
			
			//修复'多\问题
			$str = str_replace("\'","'",$str);
			
			//输出数据
			$out = str_replace('\"','"',$str);
		}
		
		//单独语言文件包
		if($this->LangData[$id]=='o(O_O)o.ET Language.o(*_*)o'){
			unset($etl);
			include_once($this->LangDir.$this->Language.".".$id.".php");
			$this->LangData[$id] = $etl;
		}
		
		//输出部分要做处理
		if($this->RunType=='Replace'){
			if($this->LangData[$id]!=''){
				return $this->LangData[$id] = str_replace('"','\"',$this->LangData[$id]);
			}else{
				return $out = str_replace('"','\"',$out);
			}
		}
		
		return (trim($this->LangData[$id]))?$this->LangData[$id]:$out;
	}
	
	
	/**
	*	换行函数
	*	Row(换行数,换行内容);
	*	Row("5,</tr><tr>");
	*/
	function Row(
				$Num=''
			){
		$Num = trim($Num);
		if($Num!=''){
			$Nums  = explode(",",$Num);
			$Numr  = ((int)$Nums[0]>0)?(int)$Nums[0]:2;
			$input = (trim($Nums[1])=='')?'</tr><tr>':$Nums[1];
			
			if(trim($Nums[1])!=''){
				$Co	 	= explode(":",$Nums[1]);
				$OutStr = "if(\$_i%$Numr===0){\$row_count++;echo(\$row_count%2===0)?'</tr><tr bgcolor=\"$Co[0]\">':'</tr><tr bgcolor=\"$Co[1]\">';}";
			}else{
				$OutStr = "if(\$_i%$Numr===0){echo '$input';}";
			}
			return ($this->RunType=='Cache')?"<?".$OutStr."?>":'";'.$OutStr.'echo "';
		}
	}
	
	
	/**
	*	间隔变色
	*	Color(两组颜色代码);
	*	Color('#FFFFFF,#DCDCDC');
	*/
	function Color(
				$color=''
			){
		if($color!=''){
			$Co = explode(",",$color);
			if(count($Co)==2){
				$OutStr = "echo(\$_i%2===0)?'$Co[0]':'$Co[1]';";
				return ($this->RunType=='Cache')?"<?".$OutStr."?>":'";'.$OutStr.'echo "';
			}
		}
	}
	
	
	/**
	*	映射图片地址
	*/
	function Dirs(
				$adds=''
			){
		$adds_ary = explode(",",$adds);
		if(is_array($adds_ary)){
			$this->ImgDir = (is_array($this->ImgDir))?@array_merge($adds_ary, $this->ImgDir):$adds_ary;
		}
	}
	
	
	/**
	*  编译解析处理
	*/
	function CompilePHP(
				$content='',
				$type=''
			){
		//如果没有安全文件则自动创建
		if($this->RunType=='Cache' && !is_file($this->CacheDir.'/index.htm')){
			$Ease_name   = 'Ease Template!';
			$Ease_base   = "<title>$Ease_name</title><a href='http://www.systn.com'>$Ease_name</a>";
			$this->writer($this->CacheDir.'/index.htm',$Ease_base);	$this->writer($this->CacheDir.'/index.html',$Ease_base);$this->writer($this->CacheDir.'/default.htm',$Ease_base);
		}
		
		//Fix XML
		$content = @preg_replace('/<\?(xml.+?)\?>/is', '<ET>\\1</ET>', $content);
		$content = @preg_replace($this->Compile, $this->Analysis, $content);
		$content = $this->ImgCheck($content);
		$content = @str_replace('<?','<?php ',$content);
		$content = @preg_replace('/(<?php\s*=)/is','php echo ',$content);
		return $content;
	}
	
	
	/**
	*	分析图片地址
	*/
	function ImgCheck(
				$content
			){
		//Check Image Dir
		if($this->AutoImage==1){
			$NewFileDir = $this->FileDir[$this->ThisFile];
			
   			//FIX img
			if(is_array($this->ImgDir)){
				foreach($this->ImgDir AS $rep){
					$rep = trim($rep);
					if(substr($rep,-1)=='/'){
						$rep = substr($rep,0,strlen($rep)-1);
					}
					$content = str_replace($rep.'/',$NewFileDir.$rep.'/',$content);
				}
			}
			
			//FIX Dir
			$NewFileDirs = $NewFileDir.$NewFileDir;
			if(ereg($NewFileDirs,$content)){
				$content = str_replace($NewFileDirs,$NewFileDir,$content);
			}
		}
		return $content;
	}
	
	
	/**
	*  inc编译处理
	*/
	function inc_preg(
				$content
			){
		return preg_replace('/<\!--\s*\#include file\s*=\"([a-zA-Z0-9_\.\|]{1,100})\"\s*-->/eis', '$this->inc("'.$this->TemplateDir.'\\1'.'")', preg_replace('/(\{\s*|<!--\s*)inc\:([^\{\} ]{1,100})(\s*\}|\s*-->)/eis', '$this->inc("'.$this->TemplateDir.'\\2'.'.'.$this->Ext.'",1)', $content));
	}
	
	
	/**
	*	获得所有设置与公共变量
	*/
	function Value(){
		return (is_array($GLOBALS))?array_merge($this->ThisValue,$GLOBALS):$this->ThisValue;
	}
	
	
	/**
	*	清除设置
	*/
	function clear(){
		$this->RunType = 'Replace';
	}
	
	
	/**
	*  静态文件写入
	*/
	function htm_w(
				$w_dir = '',
				$w_filename = '',
				$w_content = ''
			){
		if($w_dir && $w_filename && $w_content){
			//目录检测数量
			$w_dir_ex  = explode('/',$w_dir);
			$w_new_dir = '';	//处理后的写入目录
			unset($dvs,$fdk,$fdv,$w_dir_len);
			foreach((array)$w_dir_ex AS $dvs){
				if(trim($dvs) && $dvs!='..'){
					$w_dir_len .= '../';
					$w_new_dir .= $dvs.'/';
					if (!@is_dir($w_new_dir)) @mkdir($w_new_dir, 0777);
				}
			}
			
			
			//获得需要更改的目录数
			foreach((array)$this->FileDir AS $fdk=>$fdv){
				$w_content = str_replace($fdv,$w_dir_len.str_replace('../','',$fdv),$w_content);
			}
			
			$this->writer($w_dir.$w_filename,$w_content);
		}
	}
	
	
	/**
	*  改变静态刷新时间
	*/
	function htm_time($times=0){
		if((int)$times>0){
			$this->HtmTime = (int)$times;
		}
	}
	
	
	/**
	*  静态文件存放的绝对目录
	*/
	function htm_dir($name=''){
		if(trim($name)){
			$this->HtmDir = trim($name).'/';
		}
	}
	
	
	/**
	*  产生静态文件输出
	*/
	function HtmCheck(
				$name=''
			){
		$this->HtmID = md5(trim($name)? trim($name).'.php' : $this->Server['REQUEST_URI'].'.php' );
		//检测时间
		if(is_file($this->HtmDir.$this->HtmID) && (time() - @filemtime($this->HtmDir.$this->HtmID)<=$this->HtmTime)){
			ob_start();
				include_once $this->HtmDir.$this->HtmID;
				$HtmContent = ob_get_contents();
			ob_end_clean();
			return $HtmContent;
		}
	}
	
	
	/**
	*  打印静态内容
	*/
	function htm_p(
				$name=''
			){
		$HtmData = $this->HtmCheck($name);
		if($HtmData){
			die($HtmData);
		}
	}
	
	
	/**
	*  输出静态内容
	*/
	function htm_r(
				$name=''
			){
		return $this->HtmCheck($name);
	}
	
	
	/**
	*	引入模板系统
	*	察看当前使用的模板以及调试信息
	*/
	function inc_list(){
		if($this->IncFile!=''){
			unset($ks,$vs);
			preg_match_all('/<!--ET\:(.+?)-->/is',$this->reader($this->IncFile), $newlist);
			foreach ($newlist[1] AS $ks=>$vs) {
				$this->IncList[] = base64_decode($vs);
			}
		}
		
		if(is_array($this->IncList)){
			$EXTS = explode("/",$this->Server['REQUEST_URI']);
			$Last = count($EXTS) -1;
			//处理清除工作 START
			if(ereg('Ease_Templatepage=Clear',$EXTS[$Last]) && trim($EXTS[$Last])!=''){
				$dir_name = $this->CacheDir;
				if(file_exists($dir_name)){
					$handle=@opendir($dir_name);
					while($tmp_file=@readdir($handle)){
						if(@file_exists($dir_name.$tmp_file)){
							@unlink($dir_name.$tmp_file);
						}
					}
					@closedir($handle);
				}
				$GoURL = urldecode(preg_replace("/.+?REFERER=(.+?)!!!/","\\1",$EXTS[$Last]));
				
				die('<script language="javascript" type="text/javascript">location="'.urldecode($GoURL).'";</script>');
			}
			//处理清除工作 END
			
			$list_file	= array();
			$file_nums	= count($this->IncList);
			$AllSize	= 0;
			foreach($this->IncList AS $Ks=>$Vs){
				$FSize[$Ks] = @filesize($Vs);
				$AllSize   += $FSize[$Ks];
			}
			
			foreach($this->IncList AS $K=>$V){
				$File_Size   = @round($FSize[$K] / 1024 * 100) / 100 . 'KB';
				$Fwidth	     = @floor(100*$FSize[$K]/$AllSize);
				$list_file[] = "<tr><td colspan=\"2\" bgcolor=\"#F7F7F7\" title='".$Fwidth."%'><font color='#6F7D84' style='font-size:14px;'>$V</font>
				<font color='#B4B4B4' style='font-size:10px;'>".$File_Size."</font>
				<table border='1' width='".$Fwidth."%' style='border-collapse: collapse' bordercolor='#89A3ED' bgcolor='#4886B3'><tr><td></td></tr></table></td></tr>";
			}
			
			//连接地址
			$BackURL = preg_replace("/.+\//","\\1",$this->Server['REQUEST_URI']);
			$NowPAGE = 'http://'.$this->Server['HTTP_HOST'].$this->Server['SCRIPT_NAME'];
			$clear_link = $NowPAGE."?Ease_Templatepage=Clear&REFERER=".urlencode($BackURL)."!!!";
			$sf13    = ' style="font-size:13px;color:#666666"';
			echo '<br><table border="1" width="100%" cellpadding="3" style="border-collapse: collapse" bordercolor="#DCDCDC">
<tr bgcolor="#B5BDC1"><td><font color=#000000 style="font-size:16px;"><b>Include Templates (Num:'.count($this-> IncList).')</b></font></td>
<td align="right">';

if($this->RunType=='Cache'){
	echo '[<a onclick="alert(\'Cache file is successfully deleted\');location=\''.$clear_link.'\';return false;" href="'.$clear_link.'"><font'.$sf13.'>Clear Cache</font></a>]';
}

echo '</td></tr><tr><td colspan="2" bgcolor="#F7F7F7"><table border="0" width="100%" cellpadding="0" style="border-collapse: collapse">
<tr><td'.$sf13.'>Cache File ID: <b>'.substr($this->TplID,0,-1).'</b></td>
<td'.$sf13.'>Index: <b>'.((count($this->FileList)==0)?'False':'True').'</b></td>
<td'.$sf13.'>Format: <b>'.$this->Ext.'</b></td>
<td'.$sf13.'>Cache: <b>'.($this->RunType == 'Replace'?'Cache False':$this->CacheDir).'</b></td>
<td'.$sf13.'>Template: <b>'.$this->TemplateDir.'</b></td></tr>
</table></td></tr>'.implode("",$list_file)."</table>";
		}
	}
	
	
	/**
	*	读取函数
	*	reader(文件名);
	*/
	function reader(
				$filename
			){
		$get_fun = @get_defined_functions();
		return (in_array('file_get_contents',$get_fun['internal']))?@file_get_contents($filename):@implode("", @file($filename));
	}
	
	
	/**
	*	写入函数
	*	writer(文件名,写入数据, 写入数据方式);
	*/
	function writer(
				$filename, 
				$data='', 
				$mode='w'
			){
		if(trim($filename)){
			$file = @fopen($filename, $mode);
			  $filedata = @fwrite($file, $data);
			@fclose($file);
		}
		
		if(!is_file($filename)){
			die('Sorry,'.$filename.' file write in failed!');
		}
		
	}
}
?>